utils = {
    getVerifyCode: function (min, max) {
        let code
        code = Math.floor(Math.random() * (max - min)) + min;
        return code
    },
    setLocalStorage: function (name, value) {
        let storage
        if (!name || !value) return
        if (typeof value !== 'string') {
            value = JSON.stringify(value)
        }
        storage = window.localStorage.setItem(name, value)
    },
    getLocalStorage: function (name) {
        if (!name) return
        return window.localStorage.getItem(name)
    },
    setSessionStroage: function (name, value) {
        if (!name) return
        if (typeof value !== 'string') {
            value = JSON.stringify(value)
        }
        window.sessionStorage.setItem(name,value)
    },
    getSessionStroage: function (name) {
        if (!name) return
        return window.sessionStorage.getItem(name)
    },
    newGuid: function () {
        var guid = "";
        for (var i = 1; i <= 32; i++) {
            var n = Math.floor(Math.random() * 16.0).toString(16);
            guid += n;
            if ((i == 8) || (i == 12) || (i == 16) || (i == 20))
                guid += "-";
        }
        return guid;

    },
    getTooken(){
        let appid
        appid =this.setSessionStroage('appid')
        return appid
    },
    urlEncode:function(param, key, encode) {
        if (param==null) return '';
        var paramStr = '';
        var t = typeof (param);
        if (t == 'string' || t == 'number' || t == 'boolean') {
            paramStr += '&' + key + '='  + ((encode==null||encode) ? encodeURIComponent(param) : param); 
        } else {
            for (var i in param) {
                var k = key == null ? i : key + (param instanceof Array ? '[' + i + ']' : '.' + i)
                paramStr += this.urlEncode(param[i], k, encode)
            }
        }
        return paramStr;
    
    }
    

}

module.exports = utils

